//
//  BaseCoordinator.swift
//  SwiftUi
//
//  Created by xm on 05/09/2025.
//

import Foundation


@MainActor
protocol MoviesCoordinatorProtocol {
    func showDetail(for movie: Movie)
    func showDetail(for person: Person)
}


@MainActor
@Observable
final class MoviesCoordinator: MoviesCoordinatorProtocol {
    var routes: [Route] = []
        
    init() {
        self.routes = routes
    }
    
    func showDetail(for movie: Movie) {
        
        let viewModel = MovieViewModel(movie: movie, coordinator: self)
        let route = RouteIdentifier(value: viewModel, id: \.movie.id)
        routes.append(.movieDetail(route))
        
    }
    
    func showDetail(for person: Person) {
        let viewModel = PersonViewModel(person: person, coordinator: self)
        let route = RouteIdentifier(value: viewModel, id: \.person.id)
        routes.append(.personDetail(route))
        
    }
    
  
    
    enum Route :Hashable{
        

        case movieDetail(RouteIdentifier<MovieViewModel>)
        case personDetail(RouteIdentifier<PersonViewModel>)
    }
}
